package com.imy.touch.runnable;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.graphics.Path;
import android.os.Build;
import android.os.ConditionVariable;
import android.os.SystemClock;
import android.util.Log;

import com.imy.common.helper.LockHelper;
import com.imy.common.util.ALog;
import com.imy.common.util.ToastUtil;
import com.imy.touch.TouchCore;
import com.imy.touch.bean.GesturePoint;

public class ClickedGestureRunnable extends BaseGestureRunnable implements Runnable {

    public ClickedGestureRunnable(GesturePoint point) {
        super(point);
    }


    @Override
    public void run() {
        if (checkUserRoot()){
            down4Root();
            SystemClock.sleep(300);
            up4Root();
        }else {
            clicked4Accessibility();
        }
    }
    private void  clicked4Accessibility(){
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
            Path mPath=new Path();
            mPath.moveTo(mPoint.x,mPoint.y);
            GestureDescription.Builder builder = new GestureDescription.Builder();
            long clickTime=1L;
            builder.addStroke(new GestureDescription.StrokeDescription(mPath,0,clickTime));
            TouchCore.get().getCallService().getService().dispatchGesture(builder.build(),
                new AccessibilityService.GestureResultCallback() {
                    @Override
                    public void onCompleted(GestureDescription gestureDescription) {
                        ALog.i(" clicked onCompleted");

                    }
                    @Override
                    public void onCancelled(GestureDescription gestureDescription) {
                        ALog.i("clicked onCancelled");
                    }
                },null);
        }else {
            unSupportVer();
        }
    }


}
